package com.example.service.Impl;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.example.dao.StudentDao;
import com.example.entity.Student;
import com.example.service.IStudentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class StudentServiceImpl implements IStudentService {

    @Resource
    private StudentDao studentDao;

    @Override
    public Student selectStudentById(Integer id) {
        return studentDao.selectById(id);
    }

    // 使用@SentinelResource 注解用来标识资源是否被限流、降级
    @SentinelResource(value = "getById",blockHandler = "handleException")
    public Student getById(Integer id) {
        return studentDao.selectById(id);
    }

    public Student handleException(Integer id, BlockException ex) {
        Student userEntity = new Student();
        userEntity.setName("===被限流降级啦===");
        return userEntity;
    }

}
